﻿Imports Microsoft.Xna.Framework.Content
Imports Runa.Resources.ContentReader.VectorFont
Imports Microsoft.Xna.Framework

Namespace Global.Runa.Resources.ContentReader

    Public Class VectorFontCharacterReader
        Inherits ContentTypeReader(Of VectorFontCharacter)

        Protected Overloads Overrides Function Read(input As Microsoft.Xna.Framework.Content.ContentReader, existingInstance As VectorFont.VectorFontCharacter) As VectorFont.VectorFontCharacter
            ' Read the vertices for this font and the value for the cursor advancement
            Dim vertices As List(Of Vector2) = input.ReadObject(Of List(Of Vector2))()
            Dim advancement As Vector2 = input.ReadObject(Of Vector2)()

            ' Load the font's outline index records
            Dim outlineCount As Integer = input.ReadInt32()
            Dim outlines As New List(Of VectorFontCharacter.Outline)(outlineCount)
            For index As Integer = 0 To outlineCount - 1
                Dim startVertexIndex As Integer = input.ReadInt32()
                Dim vertexCount As Integer = input.ReadInt32()
                outlines.Add(New VectorFontCharacter.Outline(startVertexIndex, vertexCount))
            Next

            ' Load the font's face index records
            Dim faceCount As Integer = input.ReadInt32()
            Dim faces As New List(Of VectorFontCharacter.Face)(faceCount)
            For index As Integer = 0 To faceCount - 1
                Dim firstVertexIndex As Integer = input.ReadInt32()
                Dim secondVertexIndex As Integer = input.ReadInt32()
                Dim thirdVertexIndex As Integer = input.ReadInt32()
                faces.Add(New VectorFontCharacter.Face(firstVertexIndex, secondVertexIndex, thirdVertexIndex))
            Next

            ' All done, we can construct a new character from the loaded data
            Return New VectorFontCharacter(advancement, vertices, outlines, faces)
        End Function

    End Class

End Namespace